home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / drdobbs / 1987 / 12 / holub / tdebug.c < prev   
Text File  |  1987-12-21  |  10KB  |  109 lines

  1. #include <stdio.h>                                                                            
  2. #include "kernel.h"                                                                           
  3.                                                                                               
  4. /* TDEBUG.C     Various routines that are useful for debugging but                            
  5.  *              probably won't end up in the final system.                                    
  6.  */                                                                                           
  7.                                                                                               
  8. t_tprint( t )                                                                                 
  9. TCB     *t;                                                                                   
  10. {                                                                                             
  11.     /* Print a TCB */                                                                         
  12.                                                                                               
  13.     char  **p, *str ;                                                                         
  14.     int   i;                                                                                  
  15.                                                                                               
  16.     printf("----------------- <%s> at %04x ----------------\n",                               
  17.                                                     t->tag, t );                              
  18.                                                                                               
  19.     printf("stack %04x:%04x, priority %d, timestamp %d,",                                     
  20.                      t->ss,t->sp, t->priority, t->timestamp );                                
  21.                                                                                               
  22.     printf(" wait %d, status %d\n", t->wait, t->status );                                     
  23.                                                                                               
  24.     printf("next %04x, initial sp %04x, msg %04x ",                                           
  25.                                 t->next, t->initial_sp, t->msg );                             
  26.     pstr( t->msg, 10 );                                                                       
  27.                                                                                               
  28.     printf("stack[ 0] @ %04x = %04x,  ",                                                       
  29.                                 &(t->stack)[0], (t->stack)[0]);                               
  30.     printf("stack[ 1] @ %04x = %04x\n\n",                                                      
  31.                                 &(t->stack)[1], (t->stack)[1]);                               
  32.                                                                                               
  33.     /* Print the top 15 elements of the stack */                                              
  34.                                                                                               
  35.     i = 15;                                                                                   
  36.     for( p = (char **)t->sp; p < t->initial_sp && --i>=0; p++ )                               
  37.     {                                                                                         
  38.         printf("   sp[%2d] @ %04x = %04x = ",                                                  
  39.                                 (char **)t->sp - p, p, *p);                                   
  40.         pstr( *p, 32 );                                                                       
  41.     }                                                                                         
  42.                                                                                               
  43.     if( i < 0 )                                                                               
  44.         printf("(Stack dump truncated at 15 elements)\n");                                    
  45.                                                                                               
  46.     printf("-----------------------------------------------\n");                              
  47. }                                                                                             
  48.                                                                                               
  49. /*------------------------------------------------------------*/                              
  50.                                                                                               
  51. static pstr( str, len )                                                                       
  52. char    *str;                                                                                 
  53. {                                                                                             
  54.     /* Print a string with dots instead of nonprinting                                        
  55.      * characteres                                                                            
  56.      */                                                                                       
  57.                                                                                               
  58.     putchar('<');                                                                             
  59.                                                                                               
  60.     for( len = 32 ; --len>=0 && *str ; str++ )                                                
  61.             putchar( ' ' <= *str && *str < 0x7f ? *str : '.' );                               
  62.                                                                                               
  63.     printf(">\n");                                                                            
  64. }                                                                                             
  65.                                                                                               
  66. /*------------------------------------------------------------*/                              
  67.                                                                                               
  68. t_qprint( q )                                                                                 
  69. T_QUEUE *q ;                                                                                  
  70. {                                                                                             
  71.     /* Print out the contents of a queue */                                                   
  72.                                                                                               
  73.     TCB *t;                                                                                   
  74.     int i;                                                                                    
  75.                                                                                               
  76.     if( q->signature != TQ_SIG )                                                              
  77.     {                                                                                         
  78.             printf("Queue is invalid (bad signature)\n");                                     
  79.             return;                                                                           
  80.     }                                                                                         
  81.                                                                                               
  82.     printf("-------------- Queue at %04x ----------------\n", q);                             
  83.     printf("%d/%d messages in queue, next queue at %04x\n",                                   
  84.                                 q->numele, q->q_size, q->next );                              
  85.                                                                                               
  86.     printf("Waiting tasks: ");                                                                
  87.     if( t = q->task_h )                                                                       
  88.         printf("(none)\n" );                                                                  
  89.     else                                                                                      
  90.     {                                                                                         
  91.         for( ; t ; t = t->next )                                                              
  92.         {                                                                                     
  93.             printf( "%s, ", t->tag );                                                         
  94.             if( t == q->task_t )                                                              
  95.                     printf("(end)\n");                                                        
  96.         }                                                                                     
  97.         printf("\n");                                                                         
  98.     }                                                                                         
  99.                                                                                               
  100.     printf( "head = &queue[%d], tail = &queue[%d], queue is:\n",                              
  101.                      q->headp - q->queue, q->tailp - q->queue);                               
  102.                                                                                               
  103.     for( i = 0; i < q->q_size ; i++ )                                                         
  104.     {                                                                                         
  105.             printf("queue[%d]: %04x ", i, q->queue[i] );                                      
  106.             pstr( q->queue[i], 32 );                                                          
  107.     }                                                                                         
  108.     printf("------------------------------------------------\n");                             
  109. }